package com.foreknow.demo17;

import java.io.*;

/**
 * 对象输出流与对象输入流
 * ObjectPutStream
 * ObjectOutStream
 */

public class ObjectOutputStreamDemo {
    public static void main(String[] args) {
        try {
//            FileOutputStream fos = new FileOutputStream("data.ser");//data.ser为二进制文件
//            ObjectOutputStream oos = new ObjectOutputStream(fos);
//            //将对象写入到data.ser二进制文件中
//            Employee e1 = new Employee("zhangsan ",15,"市场部");
//            oos.writeObject(e1);
//            oos.close();


            //读取文件中的对象属性
            FileInputStream fis = new FileInputStream("data.ser");
            ObjectInputStream ois = new ObjectInputStream(fis);
            Employee E1 = (Employee) ois.readObject();
//            E1.setAge(12);
//            E1.setName("tom");
            E1.showInfo();
            //结束流程
            ois.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
